package com.ruoyi.school.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.school.domain.PacDepartment;
import com.ruoyi.school.service.PacDepartmentService;
import com.ruoyi.school.mapper.PacDepartmentMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author jeremylin
 * @description 针对表【pac_department(院系表)】的数据库操作Service实现
 * @createDate 2025-11-04 05:14:40
 */
@Service
public class PacDepartmentServiceImpl extends ServiceImpl<PacDepartmentMapper, PacDepartment>
        implements PacDepartmentService {

    @Override
    public List<PacDepartment> getList(PacDepartment pacDepartment) {

        List<PacDepartment> list = lambdaQuery()
                .eq(Objects.nonNull(pacDepartment.getCollegeId()), PacDepartment::getCollegeId, pacDepartment.getCollegeId()).list();
        return list;
    }

    @Override
    public PacDepartment getDetails(PacDepartment pacDepartment) {
        if (pacDepartment.getId() == null) {
            throw new RuntimeException("id不能为空");
        }
        PacDepartment one = lambdaQuery().eq(PacDepartment::getId, pacDepartment.getId()).one();
        return one;
    }

    @Override
    public boolean add(PacDepartment pacDepartment) {
        if (save(pacDepartment)) {
            return true;
        }
        return false;
    }

    @Override
    public boolean edit(PacDepartment pacDepartment) {
        if (pacDepartment.getId() == null) {
            throw new RuntimeException("id不能为空");
        }
        if (updateById(pacDepartment)) {
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(PacDepartment pacDepartment) {
        if (pacDepartment.getId() == null) {
            throw new RuntimeException("id不能为空");
        }
        if (removeById(pacDepartment)) {
            return true;
        }
        return false;
    }

    @Override
    public List<PacDepartment> getAllList(PacDepartment pacDepartment) {
        List<PacDepartment> list = lambdaQuery().list();
        return list;
    }
}




